package little_david.finder;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import little_david.finderlibrary.Finder;
import little_david.finderlibrary.Unbinder;
import little_david.finderlibrary.finder_annotation.BindView;
import little_david.finderlibrary.finder_annotation.ClickEvent;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.btn1)
    Button btn1;

    @BindView(R.id.btn2)
    Button btn2;
    private Unbinder mUnbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //进行绑定操作
        mUnbinder = Finder.bind(this);

        btn1.setText("Hello world!");
    }

    /**
     * 可以绑定多个View
     */
    @ClickEvent({R.id.btn1, R.id.btn2})
    public void btn1Click(View view) {
        Toast.makeText(this, "My id is: " + view.getId(), Toast.LENGTH_SHORT).show();
    }

    /**
     * 进行解绑操作，释放资源
     */
    @Override
    protected void onDestroy() {
        mUnbinder.unbind();
        super.onDestroy();
    }
}
